package com.heima.file.config;

import okhttp3.internal.http2.Header;

class Solution {

    public static int test(int[] nums, int target) {

        int res = nums[0]+nums[1]+nums[2];
        if (target<=res){
            return res;
        }

        for (int i = 0; i < nums.length; i++) {
            for (int j = i+1; j < nums.length; j++) {
                for (int k=j+1 ; k < nums.length; k++) {
                    int sum = nums[i] + nums[j] + nums[k];
                    if (Math.abs(target-res)>=Math.abs(target-sum)){
                        res = sum;
                    }
                }
            }
        }
        return res;

    }

    public static void main(String[] args) {

        int a[] = {-1,2,1,-4};
        int test = test(a, 2);
        System.out.println(test);
    }


}